package mybox.engine.linefollower;

import java.awt.Polygon;
import java.io.IOException;
import java.util.ArrayList;

import mybox.engine.File4Qcad;
import mybox.engine.Line;
import mybox.engine.QVector;
import mybox.engine.ReferenceIOutput;

public class Polygon2QCAD {
	
	public static void show(ArrayList<Polygon> polygonList) throws SecurityException, IOException {
		show(polygonList,0,polygonList.size()-1);		
	}
	
	public static void show(ArrayList<Polygon> polygonList, int from, int to) throws SecurityException, IOException {
		
		File4Qcad file4qcad = new File4Qcad(ReferenceIOutput.testoutputFile());
		int listCount=0;
		for (Polygon polygon:polygonList) {
			if (listCount>=from && listCount<=to) {
				for (int lineIdx=0;lineIdx<polygon.npoints-1;lineIdx++) {				
						QVector begin = new QVector(polygon.xpoints[lineIdx], polygon.ypoints[lineIdx]);
						QVector end = new QVector(polygon.xpoints[(lineIdx+1)%polygon.npoints],polygon.ypoints[(lineIdx+1)%polygon.npoints]);
						Line line = new Line(file4qcad, begin, end);
						line.draw();
				}
			}
			listCount++;
		}
		file4qcad.close();
	}
	
	public static ArrayList<Polygon> merge(ArrayList<Polygon> listA, ArrayList<Polygon> listB) {
		ArrayList<Polygon> retList = new ArrayList<Polygon>();
		for (Polygon polygon:listA) retList.add(polygon);
		for (Polygon polygon:listB) retList.add(polygon);		
		return retList;
	}

}
